<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>百慧智慧wms仓库</title>
  <link href="../layui/css/layui.css" rel="stylesheet">
</head>
<body>

    <!-- 条件查询 -->
    <div class="layui-fluid" style="border-bottom: 0.5px solid #ccc;">
        <div class="layui-row">
            <form>
                <div class="layui-col-md4">
                    <div class="layui-form-item">
                        <label class="layui-form-label">仓库</label>
                        <div class="layui-input-block" id="repoId"></div>
                    </div>
                </div>
                <div class="layui-col-md4">
                    <div class="layui-form-item">
                        <label class="layui-form-label">产品</label>
                        <div class="layui-input-block" id="prodId"></div>
                    </div>
                </div>
                <div class="layui-col-md4" style="display: flex;justify-content: center;">
                    <div class="layui-form-item">
                        <button type="button" lay-submit lay-filter="search" class="layui-btn layui-btn-primary layui-border-blue"> <i class="layui-icon layui-icon-search"></i> 搜索</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <!-- 数据展示 -->
    <div class="layui-fluid">
        <table id="demo" lay-filter="test"></table>
    </div>

<script src="../layui/layui.js"></script>
<script src="../js/xm-select.js"></script>
<script>

    layui.use(["jquery","form","layer","table"],function () {

        let $ = layui.jquery;
        let layer = layui.layer;
        let table = layui.table;
        let form = layui.form;

        /*
         * 数据表格生成
         */
        table.render({
            elem:"#demo",
            url:"/getRecordStockPage",
            page:{
                prev:'上一页',
                next:'下一页'
            },
            limit:5,
            limits:[5,10,15,20,25],
            request:{
                pageName: 'pageNo',
                limitName:'pageSize'
            },
            parseData:function(res){
                return {
                    "code": res.code,
                    "msg": res.msg,
                    "count": res.obj.count,
                    "data": res.obj.data
                }
            },
            cols:[
                [
                    {
                        title: '序号',
                        type:'numbers',
                        width:'10%'
                    },
                    {
                        title: '仓库名称',
                        sort: true,
                        templet:function (d) {
                            return d.repository.repoName;
                        }
                    },
                    {
                        title: '产品名称',
                        sort: true,
                        templet:function (d) {
                            return d.product.productName;
                        }
                    },
                    {
                        field: 'productStock',
                        title: '产品库存'
                    },
                    {
                        field: 'createTime',
                        title: '创建时间',
                        sort: true,
                        width:'18%'
                    },
                    {
                        field: 'updateTime',
                        title: '更新时间',
                        sort: true,
                        width:'18%'
                    },
                    {
                        field: 'isDelete',
                        title: '是否有效',
                        templet:function (d) {
                            return d.isDelete==1?'<span class="layui-badge layui-bg-blue">有效</span>':'<span class="layui-badge layui-bg-orange">无效</span>';
                        }
                    }
                ]
            ]
        });

        /**
         * 搜索事件绑定
         */
        form.on("submit(search)",function (obj){
            //重新获取数据表格首页数据(根据搜索条件查询出来的数据)
            table.reload("demo",{
                page:{
                    curr:1
                },
                where:{
                    userName:obj.field.userName,
                    userTel:obj.field.userTel,
                    startTime:obj.field.startTime,
                    endTime:obj.field.endTime
                }
            })
        });

        /**
         * 产品列表
         */
        $.getJSON("/getProductList",function (d) {
            if(d.code==0){
                let r = d.obj;
                xmSelect.render({
                    el:"#prodId",
                    data:r,
                    filterable: true,/*开启搜索模式*/
                    max: 1, /* 选择一条 */
                    tips:"产品名称",/* 修改背景提示 */
                    searchTips:"搜索产品名",/*搜索提示*/
                    prop:{  /*修改下拉框默认属性*/
                        name:"productName",
                        value:"productId"
                    },
                    theme: { /*主题*/
                        color: '#0081ff'
                    }
                });
            }
        });


        /**
         * 仓库列表
         */
        $.getJSON("/getRepositoryList",function (d) {
            if(d.code==0){
                let r = d.obj;
                xmSelect.render({
                    el:"#repoId",
                    data:r,
                    filterable: true,/*开启搜索模式*/
                    max: 1, /* 选择一条 */
                    tips:"仓库名称",/* 背景提示 */
                    searchTips:"搜索仓库",/*搜索提示*/
                    prop:{  /*修改下拉框默认属性*/
                        name:"repoName",
                        value:"repoId"
                    },
                    theme: { /*主题*/
                        color: '#0081ff'
                    }
                });
            }
        });


    });


</script>
</body>
</html>